package com.atguigu.boot.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 　Spring的事件遵循的流程：
 *
 * 自定义事件，继承ApplicationEvent（org.springframework.context.ApplicationEvent）
 * 自定义监听，实现ApplicationListener<T>（org.springframework.context.ApplicationListener）接口，然后实现onApplicationEvent方法
 * 使用容器触发事件
 *
 * @author lihj
 * @version 1.0.0
 * @title CustomListenerController
 * @description <TODO description class purpose>
 * @date 2023/7/11
 */
@RestController
@RequestMapping(value="/listener")
public class CustomListenerController {
    @Autowired
    @Qualifier(value = "customListenerService")
    private CustomListenerService customListenerService;

    @ResponseBody
    @RequestMapping(value="/testevent")
    public String testEvent() {
        System.out.println("CustomListenerController 发布监听 开始");
        customListenerService.publish("测试监听");
        System.out.println("CustomListenerController 发布监听 结束");
        return "success";
    }
}
